package com.stockz.ui.swing.charting.widget;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import javax.swing.DefaultComboBoxModel;

import com.stockz.core.manager.ScripManager;
import com.stockz.core.model.Scrip;
import com.stockz.ui.swing.widget.FilteredComboBox;

public class ScripNameComboBox extends FilteredComboBox{
	private static final long serialVersionUID = 8221076684576592103L;

	private ScripManager scripManager;
	
	public ScripNameComboBox(ScripManager scripManager){
		this.scripManager = scripManager;
		reset();
	}
	
	/**
	 * A no-arg constructor to for scenarios where we have to show watchlist or scan results etc
	 */
	public ScripNameComboBox() {
		
	}
	
	
	public void reset(){
		List<Scrip> scripList = scripManager.getAllScrip("Q");
		if(scripList != null && !scripList.isEmpty()){
			Collections.sort(scripList, new Comparator<Scrip>(){
				@Override
				public int  compare(Scrip o1, Scrip o2) {
					return o1.getName().compareTo(o2.getName());
				}
			});
			setModel(new DefaultComboBoxModel(scripList.toArray()));
		}
	}
}
